﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeGeneratorBootstrap.Models;

namespace CodeGeneratorBootstrap.Template.Web.Views
{
	public partial class ListByLocation:ITemplate
	{
		public MetaData Data { get; set; }
		public List<LookupClassModel> lookups { get; set; }
		public List<PickupListModel> pickuplist { get; set; }

		public string Filename
		{
			get { return "List{ClassName}ByLocation.cshtml"; }
		}

		public bool IsGenerateOneTime { get { return false; } }
		public bool IsGenerateFolder { get { return true; } }
		public bool IsRequiredOnlyOneMember { get { return true; } }
		public GenerateStyle GenerateStyle { get { return GenerateStyle.Normal; } }

		public List<AttributeModel> GetAllGeoLocationAttributes()
		{
			List<AttributeModel> allLocationAttibute = new List<AttributeModel>();
			foreach (AttributeModel attribute in Data.Models[0]._attributes)
			{
				if (attribute.DataType.Name.Equals("GeoLocation"))
				{
					allLocationAttibute.Add(attribute);
				}				
			}

			return allLocationAttibute;
		}

		public String FindPk(ClassModel model)
		{
			var Attributes = model._attributes;
			if (Attributes.Count > 0)
			{
				foreach (var rowItem in Attributes)
				{
					if (rowItem.Pk)
					{
						return rowItem.Name;
					}
				}
			}
			return "Id";
		}
	}
}
